
#创建一个名为“shopping_list.txt"的文件，写入你本周要购买的3样物品。编写程序读取该文件内容，并在每行前面加上序号后打印出来。
#
with open("shopping_list.txt","w") as file:
    file.write("物品1\n物品2\n物品3")
with open("shopping_list.txt","r") as file:
    lines = file.readlines()
    for i,line in enumerate(lines,1):
        print(f"{i}. {line.strip()}")
print("-----------------")
with open("shopping_list.txt", "w", encoding="utf-8") as f:
    f.write("牛奶\n")
    f.write("面包\n")
    f.write("鸡蛋\n")
# 读取文件内容并按序号打印
with open("shopping_list.txt", "r", encoding="utf-8") as f:
    lines = f.readlines()
    for index, line in enumerate(lines, start=1):
        # 去除每行末尾的换行符后打印
        print(f"{index}. {line.strip()}")